<!--策略库-->
<template>
  <view class="bg">
    <scroller class="scroller">

      <!--刷新-->
      <refresh @refresh="httpStrategyLibrary" :display="isRefresh ? 'show' : 'hide'">
        <loading-indicator class="load text1"></loading-indicator>
      </refresh>

      <div class="wrapper">

        <!--热门策略-->
        <div v-if="news.length">
          <div class="title">
            <div class="title-line main1"></div>
            <text class="font28 text1">{{T('热门策略')}}</text>
          </div>
          <div class="cell" v-for="(item, index) in news" v-bind:key="index">
            <COfficiai :item="item" :isVip="isVip"></COfficiai>
          </div>
        </div>
        
        <!--合约-->
        <div v-if="contracts.length">
          <div class="title">
            <div class="title-line main1"></div>
            <text class="font28 text1">{{T('合约策略')}}</text>
          </div>
          <div class="cell" v-for="(item, index) in contracts" v-bind:key="index">
            <COfficiai :item="item" :isVip="isVip"></COfficiai>
          </div>
        </div>
        
        <!--币币-->
        <div v-if="coins.length">
          <div class="title">
            <div class="title-line main1"></div>
            <text class="font28 text1">{{T('币币策略')}}</text>
          </div>
          <div class="cell" v-for="(item, index) in coins" v-bind:key="index">
            <COfficiai :item="item" :isVip="isVip"></COfficiai>
          </div>
        </div>

        <!--私有-->
        <div v-if="privates.length">
          <div class="title">
            <div class="title-line main1"></div>
            <text class="font28 text1">{{T('私有策略')}}</text>
          </div>
          <div class="cell" v-for="(item, index) in privates" v-bind:key="index">
            <CPrivate :item="item"></CPrivate>
          </div>
        </div>

        <!--购买-->
        <div v-if="buys.length">
          <div class="title">
            <div class="title-line main1"></div>
            <text class="font28 text1">{{T('购买的策略')}}</text>
          </div>
          <div class="cell" v-for="(item, index) in buys" v-bind:key="index">
            <CBuy :item="item"></CBuy>
          </div>
        </div>

        <!--AI-->
        <div v-if="ais.length">
          <div class="title">
            <div class="title-line main1"></div>
            <text class="font28 text1">{{T('AI')}}</text>
          </div>
          <div class="cell" v-for="(item, index) in ais" v-bind:key="index">
            <CAi :item="item"></CAi>
          </div>
        </div>
      </div>
    </scroller>


      <view class="ai main-bt1" @click="aiClick">
        <text class="text1">AI</text>
      </view>
  </view>
</template>

<script>


  //组件
  import COfficiai from "@/up/view/COfficiai"; 
  import CPrivate from "@/up/view/CPrivate"; 
  import CBuy from "@/up/view/CBuy"; 
  import CAi from "@/up/view/CAi"; 

  //功能
  import jnavigator from "@/_js/navigator"; 
  import modal from "@/_js/modal"; 
  import jconfig from "@/_js/config"; 

  import weexHttp from "@/_js/https"; ;
  const weexFunction = weex.requireModule("WeexFunction");

  import I18N from "@/_i18n/i18n";
  var T = I18N.t;

  export default {

    components: {
      COfficiai,
      CPrivate,
      CBuy,
      CAi
    },
    

    data() {
      return {
        T:T,

        isVip:false,
        news:[], //新手
        contracts:[], //合约
        coins:[], //币币
        privates:[], //私有的
        buys:[], //购买的
        ais:[], //AI
        
        isRefresh:false, //turn刷新中

        //过滤策略
        delectId:{'WL202X0624182847743':'SMT信号合约',
                  'WL202X0512112808681':'信号马丁'}
      };
    },

    mounted() {
      this.httpUserInfo();
      this.httpStrategyLibrary();
    },

    methods: {

      viewappear() {
        this.httpUserInfo();
      },
      
      initData(data) {

            this.privates = data.privateStrategys ? data.privateStrategys : []; //私有的
            this.buys = data.buyStrategys ? data.buyStrategys : []; //购买的
            this.ais = data.aiStrategys ? data.aiStrategys : []; //AI

            var news = []; //新手
            var contracts = []; //合约
            var coins = []; //币币
            for (let index = 0; index < data.publicStrategys.length; index++) {
              var strategy = data.publicStrategys[index];
              //2021.11.5 过滤特殊策略
              if (this.delectId[strategy.strategyId]) {
                continue;
              }

              if (strategy.strategyTag) {
                news.push(strategy);
              } else if (strategy.type == 'contract') {
                contracts.push(strategy);
              } else {
                coins.push(strategy);
              }
            }

            this.news = news; //新手
            this.contracts = contracts; //合约
            this.coins = coins; //币币
      },

      /********************************** HTTP*/
      //http用户信息
      httpUserInfo() {

        if(!jconfig.isLogin) return;
        
        var param = {};
        weexHttp.postX("userV2/userDetail", param, true,(data) => {
          if (data.status == 200) {
            data = data.data;
            var info = data.account;
            this.isVip = info.member != 'LV0';
          } else {
          }
        });
      },

      //http策略库
      httpStrategyLibrary(){
        if (this.isRefresh) return;
        this.isRefresh = true;

        var param = {};
        weexHttp.post("strategyV3/strategyLibrary",param, true,(data)=>{
          this.isRefresh = false;
          if(data.status == 200){
            var datas = data.data;
            this.initData(datas);
          } else {
            modal.toast(data.msg);
          }
        });
      },

      /********************************** 点击*/
      aiClick() {
        if (!jconfig.forceLogin()) return;
        jnavigator.open('', 'ai/ai')
      },
    }
  }

</script>


<style src="@/_css/style.css"></style>
<style scoped>
.bg {
  flex: 1;
}
.ai {
  position: absolute;
  right: 40px;
  bottom: 80px;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  /* background-color: #2F364B; */
  /* background-color: #1677fe;
  font-size: 60px; */
}


.scroller {
  flex: 1;
  align-items: center;
}
.wrapper{
  width: 750px;
  padding-left: 20px;
  padding-right: 20px;
  margin-top: 20px;
}
.load {
  height: 40px;
  width: 40px;
}

/*********************** 内容*/
.title {
  flex-direction: row;
  align-items: center;
  margin-bottom: 20px;
}
.title-line {
  width: 6px;
  height: 28px;
  border-radius: 3px;

  margin-right: 16px;
}
.cell {
  margin-bottom: 40px;
}
</style>